package com.zj.open.wechat.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zj.open.wechat.dto.AbstractMessage;
import com.zj.open.wechat.dto.event.SubscribeEvent;
import com.zj.open.wechat.dto.msg.LinkMessage;
import com.zj.open.wechat.dto.msg.TextMessage;
import com.zj.open.wechat.service.processor.DefaultMessageProcessor;
import com.zj.open.wechat.service.processor.LinkMessageProcessor;
import com.zj.open.wechat.service.processor.MessageProcessor;
import com.zj.open.wechat.service.processor.SubscribeEventProcessor;
import com.zj.open.wechat.service.processor.TextMessageProcessor;

@Component
public class MessageProcessorFactory {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    LinkMessageProcessor linkMessageProcessor;
    @Autowired
    TextMessageProcessor textMessageProcessor;
    @Autowired
    SubscribeEventProcessor subscribeEventProcessor;
    @Autowired
    DefaultMessageProcessor defaultMessageProcessor;

    @SuppressWarnings("rawtypes")
    public MessageProcessor getInstance(AbstractMessage message) {
        logger.info(message.getClass().getName());

        if (message instanceof LinkMessage) {
            return linkMessageProcessor;
        } else if (message instanceof TextMessage) {
            return textMessageProcessor;
        } else if (message instanceof SubscribeEvent) {
            return subscribeEventProcessor;
        } else {
            return defaultMessageProcessor;
        }

    }

}
